//
//  ModuleService.swift
//  
//
//  Created by 孙长坦 on 2022/4/6.
//

import Foundation
import RxSwift
import Moya
import RxMoya
import LibNetwork
import Logging

class ModuleService {
    
    static let shared = ModuleService()
    
    var logger = Logger(label: "ModuleManager.ModuleService")
    
    let moyaProvider: MoyaProvider<ModuleAPI>
    
    init() {
        logger.logLevel = .debug
        moyaProvider = HttpService.shared.moyaProvider(stubClosure: MoyaProvider.immediatelyStub)
    }
    
    func pageValue(moduleType: String, moduleId: String?,
                   pageType: String, pageId: String?) -> Single<APIResult<[String: Any]>>{
        return moyaProvider
            .rx
            .requestEx(ModuleAPI.pageValue(moduleType: moduleType,
                                           moduleId: moduleId,
                                           pageType: pageType,
                                           pageId: pageId))
            .map(type: [String: Any].self)
    }
}
